<template>
  <div>
    <FormPanel
        ref="formPanel"
        :list="initForm"
        :cols="3"
        :labelWidth="110"
        :isSubmitBtn="false"
        formType="show"
        class="mtop"
     />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate' // 验证
import { getModel,toSelectData } from '@/api/cms-common/basedata';
import { region } from '@/api/cms-common/region';
export default {
  name:'infoBase',
  mixins: [dictionary,region],
  props:{
    clue:{
      type:Object,
      default:null
    }
  },
  data() {
    return {
      initForm : this.initFormFun(),
      oldData: {}
    };
  },
  watch: {
    clue: async function(){
      this.oldData = this.clue;
      //初始化是否全国上牌
       let lps = this.oldData['licenseProvinces'];//上牌省份
       let isLicenseAll = this.oldData['isLicenseAll'];//是否全国上牌
       if(isLicenseAll==10041001){//全国上牌
          this.initForm.find(item => item.fieldName==='licenseProvinces').type = 'MULTIPLE_SELECT';
          //上牌城市不可编辑
          this.initForm.find(item => item.fieldName === 'licenseCity').disabled = true;
          let lpaInitArray = [];
          if(lps!=null && typeof(lps)!='undefined' && lps!=''){
             lpaInitArray = lps.split(",");
             if(lpaInitArray!=null && lpaInitArray.length>0){
               for(let k=0;k<lpaInitArray.length;k++){
                 lpaInitArray[k] = parseInt(lpaInitArray[k]);
               }
             }
          }
          this.oldData['licenseProvinces'] = lpaInitArray;
       }else{
         if(lps!=null && typeof(lps)!='undefined' && lps!=''){
           this.oldData['licenseProvinces'] = parseInt(lps);
         }
       }
      //初始化所在市，区
      await this.initCity(this.oldData['customerProvince']);
      await this.initTown(this.oldData['customerCity']);
      //初始化所在上牌市
      await this.initLicenseCity(this.oldData['licenseProvinces']);
      //await this.initModel();
      await this.initProvince();
      this.initData();
    }
  },
  methods: {
    //初始化所在省份
    async initProvince(){
      let pl = await this.createRegionList();
      //this.initForm[6].itemList = pl;
      //this.initForm[20].itemList = pl;
      //所在省
      this.initForm.find(item => item.fieldName==='customerProvince').itemList = pl;
      //上牌省份
      this.initForm.find(item => item.fieldName==='licenseProvinces').itemList = pl;
    },
    //初始化所在市数据
    async initCity(provinceId){
       if(!provinceId || provinceId==null || typeof(provinceId)=='undefined'){
        return;
      }
      //取省数据
      let rd = await this.getRegionData();
      if(rd!=null && typeof(rd)!='undefined' && rd[provinceId]!=null && typeof(rd[provinceId])!='undefined'){
          this.cityData = rd[provinceId].children;
          let cl = this.createSubRegionList(this.cityData);
          //this.initForm[7].itemList = cl;
          //所在市
          this.initForm.find(item => item.fieldName==='customerCity').itemList = cl;
      }
      
    },
    //初始化上牌市数据
    async initLicenseCity(provinceId){
       if(!provinceId || provinceId==null || typeof(provinceId)=='undefined'){
        return;
      }
      //取省数据
      let rd = await this.getRegionData();
      if(rd!=null && typeof(rd)!='undefined' && rd[provinceId]!=null && typeof(rd[provinceId])!='undefined'){
        let cd = rd[provinceId].children;
        let cl = this.createSubRegionList(cd);
        //this.initForm[21].itemList = cl;
        this.initForm.find(item => item.fieldName==='licenseCity').itemList = cl;
      }
    },
    //初始化所在县市数据
    async initTown(cityId){
       if(!cityId || cityId==null || typeof(cityId)=='undefined'){
        return;
      }
      if(this.cityData!=null && typeof(this.cityData)!='undefined' && this.cityData[cityId]!=null && typeof(this.cityData[cityId])!='undefined'){
        let td = this.cityData[cityId].children;
        let tl = this.createSubRegionList(td);
        //this.initForm[8].itemList = tl;
        this.initForm.find(item => item.fieldName==='customerDistrict').itemList = tl;
      }
    },
    initData(){
      this.initForm.forEach(x => {
            x.initialValue = this.clue[x.fieldName];
        });
    },
    //搜索数据
    initFormFun(){
         return [{//1
              type: 'INPUT',
              label: '客户公司名称',
              fieldName: 'customerName',
              placeholder: '',
              initialValue: ''
            },
            {//2
              type: 'SELECT',
              label: '客户类型',
              fieldName: 'customerType',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2506')
            },
            {//3
              type: 'SELECT',
              label: '客户性质',
              fieldName: 'customerProperty',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2534')
            },
            {//4
              type: 'SELECT',
              label: '客户状态',
              fieldName: 'customerStatus',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2507')
            },
            {//5
              type: 'SELECT',
              label: '客户来源',
              fieldName: 'customerSource',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2508')
            },
            {//6
              type: 'DATE',
              label: '建档时间',
              fieldName: 'recordDate',
              valueFormat: 'yyyy-MM-dd',
              initialValue: '',
              placeholder: ''
            },
            {//7
              type: 'SELECT',
              label: '所在省',
              fieldName: 'customerProvince',
              placeholder: '',
              initialValue: "",
              change: (value) => {
                this.initCity(value)
              },
              itemList:  []
            },
            {//8
              type: 'SELECT',
              label: '所在市',
              fieldName: 'customerCity',
              placeholder: '',
              initialValue: "",
              itemList: [],
              change: (value) => {
                this.initTown(value)
              },
            },
            {//9
              type: 'SELECT',
              label: '所在县/区',
              fieldName: 'customerDistrict',
              placeholder: '',
              initialValue: "",
              itemList:  []
            },
            {//10
              type: 'TEXT_AREA',
              label: '详细地址',
              fieldName: 'customerAddress',
              rows: 1,
              selfCols: 2,
              initialValue: '',
              placeholder: ''
            },
            {//11
              type: 'SELECT',
              label: '客户等级',
              fieldName: 'customerLevel',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2509')
            },
            {//12
              type: 'SELECT',
              label: '所属行业分类',
              fieldName: 'industryCategory',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2510')
            },
            {//13
              type: 'SELECT',
              label: '行业地位',
              fieldName: 'industryStatus',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2511')
            },
            {//14
              type: 'SELECT',
              label: '客户采购方式',
              fieldName: 'purchaseMode',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2512')
            },
            {//15
              type: 'INPUT',
              label: '意向车型',
              fieldName: 'intentionModelName',
              rows: 2,
              selfCols: 3,
              placeholder: '',
              initialValue: ''
            },
            {//16
              type: 'INPUT_NUMBER',
              label: '预计采购数量',
              fieldName: 'estimatePurchaseNum',
              placeholder: '',
              initialValue: '',
              precision:0,
              max:99999999
            },
            {//17
              type: 'SELECT',
              label: '购车用途',
              fieldName: 'buyPurpose',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2513')
            },
            {//18
              type: 'DATE',
              label: '预计采购日期',
              fieldName: 'estimatePurchaseDate',
			  valueFormat: 'yyyy-MM',
              dateType:'month',
              initialValue: '',
              placeholder: ''
            },
            {//19
              type: 'SELECT',
              label: '预算来源',
              fieldName: 'budgetSource',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('2514')
            },
            {//20
              type: 'INPUT_NUMBER',
              label: '年度预算',
              fieldName: 'yearBudget',
              placeholder: '',
              initialValue: '',
              precision: 2,
              max:9999999999999999
            },
            {//23
              type: 'SELECT',
              label: '是否全国上牌',
              fieldName: 'isLicenseAll',
              placeholder: '请选择',
              initialValue: "",
              itemList: this.createDictList('1004')
            },
            {//21
              type: 'SELECT',
              label: '上牌省份',
              fieldName: 'licenseProvinces',
              placeholder: '',
              initialValue: "",
              disabled:true,
              selfCols:3,
              itemList: [],
              change: (value) => {
                //是否全国上牌
                let isLicenseAll = this.clue.isLicenseAll;
                if(typeof(isLicenseAll)=='undefined' || isLicenseAll != 10041001){//非全国下发时更新上牌城市，全国下发时，上牌城市不可选。
                  this.initLicenseCity(value);
                }
              }
            },
            {//22
              type: 'SELECT',
              label: '上牌城市',
              fieldName: 'licenseCity',
              placeholder: '',
              initialValue: "",
              itemList: []
            },
            {//23
              type: 'SELECT',
              label: '是否跨区销售',
              fieldName: 'isCrossSbu',
              placeholder: '',
              initialValue: "",
              itemList: this.createDictList('1004')
            },
            {//24
              type: 'INPUT',
              label: '融资渠道',
              fieldName: 'financeChannel',
              placeholder: '',
              initialValue: ''
            },
            {//25
              type: 'INPUT',
              label: '客户关键联系人',
              fieldName: 'keyLinkMan',
              placeholder: '',
              initialValue: ''
            },
            {//26
              type: 'INPUT',
              label: '联系方式',
              fieldName: 'linkPhone',
              placeholder: '',
              initialValue: ''
            },
            {//27
              type: 'TEXT_AREA',
              label: '备注',
              fieldName: 'remark',
              rows: 2,
              selfCols:3 ,
              initialValue: '',
              placeholder: ''
            }
          ]
    }
  },
}
</script>